{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "10_Export.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "toc_visible": true,
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/csaybar/EEwPython/blob/dev/10_Export.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YAXprqVQDx6o",
        "colab_type": "text"
      },
      "source": [
        "<!--COURSE_INFORMATION-->\n",
        "<img align=\"left\" style=\"padding-right:10px;\" src=\"https://sitejerk.com/images/google-earth-logo-png-5.png\" width=5% >\n",
        "<img align=\"right\" style=\"padding-left:10px;\" src=\"https://colab.research.google.com/img/colab_favicon_256px.png\" width=6% >\n",
        "\n",
        "\n",
        ">> *This notebook is part of the free course [EEwPython](https://colab.research.google.com/github/csaybar/EEwPython/blob/master/index.ipynb); the content is available [on GitHub](https://github.com/csaybar/EEwPython)* and released under the [Apache 2.0 License](https://www.gnu.org/licenses/gpl-3.0.en.html). 99% of this material has been adapted from [Google Earth Engine Guides](https://developers.google.com/earth-engine/)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IN9ycDgvDyeW",
        "colab_type": "text"
      },
      "source": [
        "<!--NAVIGATION-->\n",
        " < [Specialized Algorithms](9_SpecializedAlgorithms.ipynb) | [Contents](index.ipynb) |  \n",
        "\n",
        "<a href=\"https://colab.research.google.com/github/csaybar/EEwPython/blob/master/9_SpecializedAlgorithms.ipynb\"><img align=\"left\" src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\" title=\"Open and Execute in Google Colaboratory\"></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "M9EbU74_ESvY",
        "colab_type": "text"
      },
      "source": [
        "<center>\n",
        "<h1>Google Earth Engine with Python </h1>\n",
        "<h2> Export Data </h2>\n",
        "</center>\n",
        "<h2> Topics:</h2>\n",
        "\n",
        "1. Exporting Images\n",
        "2. Exporting Tables and vector data\n",
        "3. Exporting videos\n",
        "\n",
        "You can export images, map tiles, tables and video from Earth Engine. The exports can be sent to your Google Drive account, to [Google Cloud Storage](https://cloud.google.com/storage/) or to a new Earth Engine asset.\n",
        "\n",
        "To use Google Cloud Storage (a fee-based service), you'll need to set up a project, enable billing for the project, and create a storage bucket. See the [Cloud Storage Quickstart](https://cloud.google.com/storage/docs/quickstart-console) page for instructions. See [this guide](https://cloud.google.com/storage/docs/naming) for information on storage bucket naming. Data exported to a Cloud Storage bucket will have the bucket's [default object Access Control List (ACL)](https://cloud.google.com/storage/docs/access-control/create-manage-lists#defaultobjects). You must have write permission for the specified bucket.\n",
        "\n",
        "The following sections describe each type of export in detail."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vSUFepPPFKeJ",
        "colab_type": "text"
      },
      "source": [
        "## Connecting GEE with Google Services"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pBbqfaJ2FM0I",
        "colab_type": "text"
      },
      "source": [
        "- **Authenticate to Earth Engine**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "v6M68WksFMZ1",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install earthengine-api #earth-engine Python API"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "JLv8sJcGFPIi",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!earthengine authenticate "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rzr4BVsoFQO0",
        "colab_type": "text"
      },
      "source": [
        "- **Authenticate to Google Drive**\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZvANQSVUFRTz",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PDGdjh6qFST2",
        "colab_type": "text"
      },
      "source": [
        "- **Authenticate to Google Cloud**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xltZxJX4FTYH",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from google.colab import auth\n",
        "auth.authenticate_user()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "DZw4_4Y8FU1G",
        "colab_type": "text"
      },
      "source": [
        "## Testing the software setup"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "v7Obx9rnFZEL",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Earth Engine Python API\n",
        "import ee\n",
        "ee.Initialize()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "JolFu0OaFanc",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import folium\n",
        "\n",
        "# Define the URL format used for Earth Engine generated map tiles.\n",
        "EE_TILES = 'https://earthengine.googleapis.com/map/{mapid}/{{z}}/{{x}}/{{y}}?token={token}'\n",
        "\n",
        "print('Folium version: ' + folium.__version__)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "FYpzL3C6GW_1",
        "colab_type": "code",
        "colab": {},
        "cellView": "form"
      },
      "source": [
        "#@title Mapdisplay: Display GEE objects using folium.\n",
        "def Mapdisplay(center, dicc, Tiles=\"OpensTreetMap\",zoom_start=10):\n",
        "    '''\n",
        "    :param center: Center of the map (Latitude and Longitude).\n",
        "    :param dicc: Earth Engine Geometries or Tiles dictionary\n",
        "    :param Tiles: Mapbox Bright,Mapbox Control Room,Stamen Terrain,Stamen Toner,stamenwatercolor,cartodbpositron.\n",
        "    :zoom_start: Initial zoom level for the map.\n",
        "    :return: A folium.Map object.\n",
        "    '''\n",
        "    mapViz = folium.Map(location=center,tiles=Tiles, zoom_start=zoom_start)\n",
        "    for k,v in dicc.items():\n",
        "      if ee.image.Image in [type(x) for x in v.values()]:\n",
        "        folium.TileLayer(\n",
        "            tiles = EE_TILES.format(**v),\n",
        "            attr  = 'Google Earth Engine',\n",
        "            overlay =True,\n",
        "            name  = k\n",
        "          ).add_to(mapViz)\n",
        "      else:\n",
        "        folium.GeoJson(\n",
        "        data = v,\n",
        "        name = k\n",
        "          ).add_to(mapViz)\n",
        "    mapViz.add_child(folium.LayerControl())\n",
        "    return mapViz"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ivM6tudaGaDi",
        "colab_type": "text"
      },
      "source": [
        "# 1. Exporting images\n",
        "\n",
        "You can export images from Earth Engine in [GeoTIFF](https://trac.osgeo.org/geotiff/) or [TFRecord](https://www.tensorflow.org/api_docs/python/tf/io#TFRecords_Format_Details) format. See [Configuration Parameters](https://developers.google.com/earth-engine/exporting#configuration-parameters) for more output options.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wOBXHvKwJBbL",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 559
        },
        "outputId": "b464561c-7363-4380-dead-d1a50b1c3f14"
      },
      "source": [
        "# Load a landsat image and select three bands.\n",
        "landsat = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_123032_20140515')\\\n",
        "            .select(['B4', 'B3', 'B2'])\n",
        "\n",
        "# Create a geometry representing an export region.\n",
        "geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236])\n",
        "center = geometry.centroid().getInfo()['coordinates']\n",
        "center.reverse()\n",
        "\n",
        "Mapdisplay(center,{'landsat':landsat.getMapId()},zoom_start=7)"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL21heGNkbi5ib290c3RyYXBjZG4uY29tL2Jvb3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4YmFjNzBiODAwYjEwNTkzID0gewogICAgICAgICAgICAgICAgYmFzZV9sYXllcnMgOiB7ICJvcGVuc3RyZWV0bWFwIiA6IHRpbGVfbGF5ZXJfZGJjYmE0Y2JiNmQwNDNmNTlhOTMwOTQ4ODQ1NWJhMzksIH0sCiAgICAgICAgICAgICAgICBvdmVybGF5cyA6IHsgImxhbmRzYXQiIDogdGlsZV9sYXllcl9lNWI5ZTk3M2UzNGY0MTM3OWEzNDhlZTFkYTVlNmRhNSwgfQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfY2UwMTk1ZTQ0NzA2NDQ1MDhiYWM3MGI4MDBiMTA1OTMuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sX2NlMDE5NWU0NDcwNjQ0NTA4YmFjNzBiODAwYjEwNTkzLm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfNzc5NDBhOWFmZGVlNDIyMzkxMjZkOWEyNmU5NTAzZDgpOwogICAgICAgICAgICAKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7fafbab59ef0>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "siHosl7mJGEa",
        "colab_type": "text"
      },
      "source": [
        "## to Drive\n",
        "\n",
        "To export an image to your Drive account, use `Export.image.toDrive()`. For example, to export portions of a Landsat image, define a region to export, then call `ee.batch.Export.image.toDrive`:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fSqTvVdGHo2T",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Export the image, specifying scale and region.\n",
        "task = ee.batch.Export.image.toDrive(**{\n",
        "    'image': landsat,\n",
        "    'description': 'imageToDriveExample',\n",
        "    'folder':'Example_folder',\n",
        "    'scale': 100,\n",
        "    'region': geometry.getInfo()['coordinates']\n",
        "})\n",
        "task.start()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Mzu9gkJiK0K7",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 89
        },
        "outputId": "62f6d37e-f1e6-4a14-aed6-5b1543b46c49"
      },
      "source": [
        "import time \n",
        "while task.active():\n",
        "  print('Polling for task (id: {}).'.format(task.id))\n",
        "  time.sleep(5)"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Polling for task (id: EA6XTMEEMUTKT5XDDY5WCX77).\n",
            "Polling for task (id: EA6XTMEEMUTKT5XDDY5WCX77).\n",
            "Polling for task (id: EA6XTMEEMUTKT5XDDY5WCX77).\n",
            "Polling for task (id: EA6XTMEEMUTKT5XDDY5WCX77).\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Klwqb0soLos4",
        "colab_type": "text"
      },
      "source": [
        "## to Cloud Storage\n",
        "\n",
        "To export an image to a Google Cloud Storage bucket, use \n",
        "`ee.batch.Export.image.toCloudStorage()`. To export the Landsat image in the previous example to Cloud Storage instead of Drive, use:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "AlrN7x3LMC7S",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "outputBucket = 'bag_csaybar' #Change for your Cloud Storage bucket\n",
        "\n",
        "# Export the image, specifying scale and region.\n",
        "task = ee.batch.Export.image.toCloudStorage(**{\n",
        "    'image': landsat,\n",
        "      'description': 'imageToCOGeoTiffExample',\n",
        "    'scale': 100,\n",
        "    'region': geometry.getInfo()['coordinates'],\n",
        "    'fileFormat': 'GeoTIFF',\n",
        "    'bucket': outputBucket,\n",
        "    'formatOptions': {'cloudOptimized': True}\n",
        "})\n",
        "task.start()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "D6HAvypAQS5O",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "while task.active():\n",
        "  print('Polling for task (id: {}).'.format(task.id))\n",
        "  time.sleep(5)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TWrU9EZRQxpa",
        "colab_type": "text"
      },
      "source": [
        "## to Asset\n",
        "To export an image to an asset in your Earth Engine assets folder, use `ee.batch.Export.image.toAsset()`. To manage your Earth Engine assets, or check how much of your storage quota is in use, use the [Asset Manager](https://developers.google.com/earth-engine/asset_manager). The following example illustrates exporting portions of a Landsat image using different pyramiding policies for the same band. The pyramiding policy indicates how Earth Engine computes lower-resolution versions of the asset. Learn more about how Earth Engine handles multiple resolutions in the [scale doc](https://developers.google.com/earth-engine/scale)."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "krQburQ-SgZe",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Get band 4 from the Landsat image, copy it.\n",
        "band4 = landsat.select('B4').rename('b4_mean')\\\n",
        "               .addBands(landsat.select('B4').rename('b4_sample'))\\\n",
        "               .addBands(landsat.select('B4').rename('b4_max'))\\\n",
        "\n",
        "# Export the image to an Earth Engine asset.\n",
        "task = ee.batch.Export.image.toAsset(**{\n",
        "  'image': band4,\n",
        "  'description': 'imageToAssetExample',\n",
        "  'assetId': 'users/csaybar/exampleExport',\n",
        "  'scale': 100,\n",
        "  'region': geometry.getInfo()['coordinates']\n",
        "})\n",
        "task.start()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "30TX7kJzSshY",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 89
        },
        "outputId": "e75042e9-0c0a-4959-a082-8a0ec0ce40a8"
      },
      "source": [
        "while task.active():\n",
        "  print('Polling for task (id: {}).'.format(task.id))\n",
        "  time.sleep(5)"
      ],
      "execution_count": 33,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Polling for task (id: NPJTL74EAHRDRAECPNW3KGIY).\n",
            "Polling for task (id: NPJTL74EAHRDRAECPNW3KGIY).\n",
            "Polling for task (id: NPJTL74EAHRDRAECPNW3KGIY).\n",
            "Polling for task (id: NPJTL74EAHRDRAECPNW3KGIY).\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9_glXXPKUwg9",
        "colab_type": "text"
      },
      "source": [
        "You can provide a default pyramiding policy for every band that isn't explicitly specified by using the `'.default'` key. You may also pass in just the `'.default'` key. For example, to make all bands default to the 'sample' pyramiding policy, use `{'.default': 'sample'}`."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "B2NDjS9yVIDm",
        "colab_type": "text"
      },
      "source": [
        "# 2. Exporting tables and vector data\n",
        "\n",
        "You can export a `FeatureCollection` as CSV, SHP (shapefile), GeoJSON, KML, KMZ or TFRecord using `Export.table`. The `FeatureCollection` may represent vectors or simply a table of data. In the latter case, the features in the collection will have null geometry.\n",
        "\n",
        "Note some additional constraints when working with some file formats, including:\n",
        "\n",
        "- KML: A `FeatureCollection` exported to a KML file will have all the geometries transformed to unprojected (WGS84) coordinates.\n",
        "\n",
        "- SHP: A `FeatureCollection` exported to a Shapefile must contain features with the same geometry type and projection and must fit within the [Shapefile size limits](https://desktop.arcgis.com/en/arcmap/latest/manage-data/shapefiles/geoprocessing-considerations-for-shapefile-output.htm). Column names are truncated to 10 characters or fewer, and this must not create duplicate column names.\n",
        "\n",
        "- TFRecord: A `FeatureCollection` exported to a TFRecord file will always be compressed with the GZIP compression type. You always get exactly one TFRecord file. All numbers are coerced to float type."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5VhMvaETVkXX",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 559
        },
        "outputId": "e98a06a3-2d8e-4b5c-f9c2-1b5ba3a26147"
      },
      "source": [
        "# Make a collection of points.\n",
        "features = ee.FeatureCollection([\n",
        "  ee.Feature(ee.Geometry.Point(30.41, 59.933), {'name': 'Voronoi'}),\n",
        "  ee.Feature(ee.Geometry.Point(-73.96, 40.781), {'name': 'Thiessen'}),\n",
        "  ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {'name': 'Dirichlet'})\n",
        "])\n",
        "center = features.geometry().centroid().getInfo()['coordinates']\n",
        "center.reverse()\n",
        "Mapdisplay(center,{'feature_example':features.getInfo()},zoom_start=2)"
      ],
      "execution_count": 36,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0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IDogeyAib3BlbnN0cmVldG1hcCIgOiB0aWxlX2xheWVyXzAyNjNiYzk1MDY0YjQxYTVhMWRmNjhmNzk1MzVkNTBiLCB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiB7ICJmZWF0dXJlX2V4YW1wbGUiIDogZ2VvX2pzb25fYzhmOGFmMTQ5ZjNmNGJhZGFkMGQyNTM5MjY3YjQ1NWYsIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgIEwuY29udHJvbC5sYXllcnMoCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sX2E4YWM0ZDg4ZmNhMzRhNDNhMTZmMjk1OTE4ZTZhNmEzLmJhc2VfbGF5ZXJzLAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF9hOGFjNGQ4OGZjYTM0YTQzYTE2ZjI5NTkxOGU2YTZhMy5vdmVybGF5cywKICAgICAgICAgICAgICAgIHtwb3NpdGlvbjogJ3RvcHJpZ2h0JywKICAgICAgICAgICAgICAgICBjb2xsYXBzZWQ6IHRydWUsCiAgICAgICAgICAgICAgICAgYXV0b1pJbmRleDogdHJ1ZQogICAgICAgICAgICAgICAgfSkuYWRkVG8obWFwXzZhMzc0OTBiMWNiNTQ5ZGU5ZjMwMjYzYzBhYmY4OGNkKTsKICAgICAgICAgICAgCiAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7faf9e31f780>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 36
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aiREOJ52Vo0N",
        "colab_type": "text"
      },
      "source": [
        "## to Drive\n",
        "To export a FeatureCollection to your Drive account, use \n",
        "ee.batch.Export.table.toDrive(). For example:\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZuOMX_9rVpXP",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Export the FeatureCollection to a KML file.\n",
        "task = ee.batch.Export.table.toDrive(**{\n",
        "  'collection': features,\n",
        "  'description':'vectorsToDriveExample',\n",
        "  'fileFormat': 'SHP'\n",
        "})\n",
        "task.start()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aHXSCUiXXtLY",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 71
        },
        "outputId": "8cb5204c-507d-4119-cb75-43425c5808d3"
      },
      "source": [
        "while task.active():\n",
        "  print('Polling for task (id: {}).'.format(task.id))\n",
        "  time.sleep(5)"
      ],
      "execution_count": 40,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Polling for task (id: 4E4HVWB2KZWDXQPGN6YYKRHY).\n",
            "Polling for task (id: 4E4HVWB2KZWDXQPGN6YYKRHY).\n",
            "Polling for task (id: 4E4HVWB2KZWDXQPGN6YYKRHY).\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5UqUnikUYLms",
        "colab_type": "text"
      },
      "source": [
        "## to Cloud Storage\n",
        "\n",
        "To export a `FeatureCollection` to Cloud Storage, use ee.batch.Export.table.toCloudStorage(). For example, using the features defined previously:\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BEtZ8ct0YXYk",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "outputBucket = 'bag_csaybar' #Change for your Cloud Storage bucket\n",
        "\n",
        "# Export a KML file to Cloud Storage.\n",
        "task = ee.batch.Export.table.toCloudStorage(**{\n",
        "  'collection': features,\n",
        "  'description':'vectorsToCloudStorageExample',\n",
        "  'bucket': outputBucket,\n",
        "  'fileNamePrefix': 'exampleTableExport',\n",
        "  'fileFormat': 'KML'    \n",
        "})\n",
        "\n",
        "task.start()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "njKq3leXZB8o",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "305691c6-dc9e-400b-e562-72648fd827f6"
      },
      "source": [
        "while task.active():\n",
        "  print('Polling for task (id: {}).'.format(task.id))\n",
        "  time.sleep(5)"
      ],
      "execution_count": 43,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Polling for task (id: RYELOVWIMRPQC45R3OHDGV3Z).\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CVwF_khsatOS",
        "colab_type": "text"
      },
      "source": [
        "## to Asset\n",
        "To export a FeatureCollection as an Earth Engine asset, use `ee.batch.Export.table.toAsset()`. For example, using the features defined previously:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-JTNZNT8auuD",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Export an ee.FeatureCollection as an Earth Engine asset.\n",
        "task = ee.batch.Export.table.toAsset(**{\n",
        "    'collection': features,\n",
        "    'description':'exportToTableAssetExample',\n",
        "    'assetId': 'users/csaybar/exampleExport'\n",
        "})\n",
        "task.start()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ALCjSERPbWbL",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 89
        },
        "outputId": "0d9ac78d-d4f7-423d-80a0-fa6df5ab722d"
      },
      "source": [
        "while task.active():\n",
        "  print('Polling for task (id: {}).'.format(task.id))\n",
        "  time.sleep(5)"
      ],
      "execution_count": 46,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Polling for task (id: 2Y6LO3NGZAVXFS55QFZODUIO).\n",
            "Polling for task (id: 2Y6LO3NGZAVXFS55QFZODUIO).\n",
            "Polling for task (id: 2Y6LO3NGZAVXFS55QFZODUIO).\n",
            "Polling for task (id: 2Y6LO3NGZAVXFS55QFZODUIO).\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Ym3RcAfzbYwT",
        "colab_type": "text"
      },
      "source": [
        "There are several limitations on the size and shape of Earth Engine table assets:\n",
        "\n",
        "- Maximum of 100 million features\n",
        "\n",
        "- Maximum of 1000 properties (columns)\n",
        "\n",
        "- Maximum of 100,000 vertices for each row's geometry\n",
        "\n",
        "- Maximum of 100,000 characters per string value"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jj0ZZfj2bjNP",
        "colab_type": "text"
      },
      "source": [
        "# 3. Exporting video\n",
        "\n",
        "To export ordered image collections as video, where frames are defined by images in the collection, use `Export.video()`. You can configure the way the `ImageCollection` is turned into video by setting frame rate, scale and dimensions. The video will be encoded as an MP4."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aUlrKybYdzft",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 559
        },
        "outputId": "dcba640f-69c8-49aa-bee0-4e80191a0a4b"
      },
      "source": [
        "# Load a Landsat 5 image collection.\n",
        "# 1. San Francisco Bay.\n",
        "# 2. Filter cloudy scenes.\n",
        "# 3. Get 20 years of imagery.\n",
        "# 4. Need to have 3-band imagery for the video.\n",
        "# 5. Need to make the data 8-bit.\n",
        "collection = ee.ImageCollection('LANDSAT/LT05/C01/T1_TOA')\\\n",
        "               .filter(ee.Filter.eq('WRS_PATH', 44))\\\n",
        "               .filter(ee.Filter.eq('WRS_ROW', 34))\\\n",
        "               .filter(ee.Filter.lt('CLOUD_COVER', 30))\\\n",
        "               .filterDate('1991-01-01','2011-12-30')\\\n",
        "               .select(['B4', 'B3', 'B2'])\\\n",
        "               .map(lambda img:img.multiply(512).uint8())\n",
        "\n",
        "# Define an area to export.\n",
        "polygon = ee.Geometry.Rectangle([-122.7286, 37.6325, -122.0241, 37.9592]);\n",
        "center = polygon.centroid().getInfo()['coordinates']\n",
        "center.reverse()\n",
        "Mapdisplay(center,{'SF LANDSAT':collection.first().getMapId()})"
      ],
      "execution_count": 62,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVM9ZmFsc2U7IExfTk9fVE9VQ0g9ZmFsc2U7IExfRElTQUJMRV8zRD1mYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NvZGUuanF1ZXJ5LmNvbS9qcXVlcnktMS4xMi40Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS40LjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZX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h0dHBzOi8ve3N9LnRpbGUub3BlbnN0cmVldG1hcC5vcmcve3p9L3t4fS97eX0ucG5nJywKICAgICAgICB7CiAgICAgICAgImF0dHJpYnV0aW9uIjogbnVsbCwKICAgICAgICAiZGV0ZWN0UmV0aW5hIjogZmFsc2UsCiAgICAgICAgIm1heE5hdGl2ZVpvb20iOiAxOCwKICAgICAgICAibWF4Wm9vbSI6IDE4LAogICAgICAgICJtaW5ab29tIjogMCwKICAgICAgICAibm9XcmFwIjogZmFsc2UsCiAgICAgICAgIm9wYWNpdHkiOiAxLAogICAgICAgICJzdWJkb21haW5zIjogImFiYyIsCiAgICAgICAgInRtcyI6IGZhbHNlCn0pLmFkZFRvKG1hcF84NjFlNTZlNDc0ZTY0OTllOWVlNzBhZmQwNjMyYWE3Myk7CiAgICB2YXIgdGlsZV9sYXllcl81N2UyMzFmMDRhMGQ0YWZiOGQ4NDJjYzE0ZjZiNzNmYyA9IEwudGlsZUxheWVyKAogICAgICAgICdodHRwczovL2VhcnRoZW5naW5lLmdvb2dsZWFwaXMuY29tL21hcC80ZWVmZDNjY2JhMGVmZjM4NjA0NjVjNTMwN2JiZGMwOC97en0ve3h9L3t5fT90b2tlbj0xMTA0ODUyZGYzODVjYTAwN2Q4YTc1MDZhYWI0MDNkMycsCiAgICAgICAgewogICAgICAgICJhdHRyaWJ1dGlvbiI6ICJHb29nbGUgRWFydGggRW5naW5lIiwKICAgICAgICAiZGV0ZWN0UmV0aW5hIjogZmFsc2UsCiAgICAgICAgIm1heE5hdGl2ZVpvb20iOiAxOCwKICAgICAgICAibWF4Wm9vbSI6IDE4LAogICAgICAgICJtaW5ab29tIjogMCwKICAgICAgICAibm9XcmFwIjogZmFsc2UsCiAgICAgICAgIm9wYWNpdHkiOiAxLAogICAgICAgICJzdWJkb21haW5zIjogImFiYyIsCiAgICAgICAgInRtcyI6IGZhbHNlCn0pLmFkZFRvKG1hcF84NjFlNTZlNDc0ZTY0OTllOWVlNzBhZmQwNjMyYWE3Myk7CiAgICAKICAgICAgICAgICAgdmFyIGxheWVyX2NvbnRyb2xfMDNmZDcwZTI1MTZiNDFiNDkxNmY5ODhlYjE5M2Y5NzEgPSB7CiAgICAgICAgICAgICAgICBiYXNlX2xheWVycyA6IHsgIm9wZW5zdHJlZXRtYXAiIDogdGlsZV9sYXllcl9hMzk1YWE0OTJhYTU0ZTM5YmFiMmI1NTU5MDU1NzExYywgfSwKICAgICAgICAgICAgICAgIG92ZXJsYXlzIDogeyAiU0YgTEFORFNBVCIgOiB0aWxlX2xheWVyXzU3ZTIzMWYwNGEwZDRhZmI4ZDg0MmNjMTRmNmI3M2ZjLCB9CiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF8wM2ZkNzBlMjUxNmI0MWI0OTE2Zjk4OGViMTkzZjk3MS5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfMDNmZDcwZTI1MTZiNDFiNDkxNmY5ODhlYjE5M2Y5NzEub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7cG9zaXRpb246ICd0b3ByaWdodCcsCiAgICAgICAgICAgICAgICAgY29sbGFwc2VkOiB0cnVlLAogICAgICAgICAgICAgICAgIGF1dG9aSW5kZXg6IHRydWUKICAgICAgICAgICAgICAgIH0pLmFkZFRvKG1hcF84NjFlNTZlNDc0ZTY0OTllOWVlNzBhZmQwNjMyYWE3Myk7CiAgICAgICAgICAgIAogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
            ],
            "text/plain": [
              "<folium.folium.Map at 0x7faf9e2dbcf8>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 62
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Kl_-NyySd050",
        "colab_type": "text"
      },
      "source": [
        "## to Drive\n",
        "\n",
        "Export video to your Drive account with `ee.batch.Export.video.toDrive`. For example, the following export makes a video from 20 years of Landsat imagery:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Iq3JDMCAdKmd",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Export (change dimensions or scale for higher quality).\n",
        "task = ee.batch.Export.video.toDrive(**{\n",
        "    'collection': collection,\n",
        "    'description': 'sfVideoExample',\n",
        "    'dimensions': 720,\n",
        "    'folder':'Example_folder',\n",
        "    'framesPerSecond': 12,\n",
        "    'region': polygon.getInfo()['coordinates']\n",
        "})\n",
        "task.start()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "g-NZ2rsNd4xF",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "while task.active():\n",
        "  print('Polling for task (id: {}).'.format(task.id))\n",
        "  time.sleep(5)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0lLSrXEAeIm9",
        "colab_type": "text"
      },
      "source": [
        "Note that the frame rate and dimensions can be set from a dictionary of parameters passed to the export. Adjust these parameters to customize the video. Also note that the input ImageCollection is required to have 3-band (RGB), 8-bit images. In this example, the 8-bit, 3-band format is explicitly set. Alternatively, map a function which calls `image.visualize()` over the collection. See [the section on Visualization images](https://developers.google.com/earth-engine/image_visualization#visualization-images) for details. Video exports can take a significant amount of time to complete, so it's not unusual to see the export task running for an extended period."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Im-NP5bweGcA",
        "colab_type": "text"
      },
      "source": [
        "## to Cloud Storage\n",
        "\n",
        "To export a video to Cloud Storage, use Export.video.toCloudStorage(). For example, using the ImageCollection from the previous example:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6L_P318ve0hD",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "outputBucket = 'bag_csaybar' #Change for your Cloud Storage bucket\n",
        "\n",
        "# Export video to cloud storage.\n",
        "task = ee.batch.Export.video.toCloudStorage(**{\n",
        "    'collection': collection,\n",
        "    'description': 'sfVideoExampleToCloud',\n",
        "    'dimensions': 720,\n",
        "    'folder':'Example_folder',\n",
        "    'bucket': outputBucket,\n",
        "    'framesPerSecond': 12,\n",
        "    'region': polygon.getInfo()['coordinates']\n",
        "})\n",
        "task.start()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "EYUFeS1rfIDc",
        "colab_type": "text"
      },
      "source": [
        "<!--NAVIGATION-->\n",
        " < [Specialized Algorithms](9_SpecializedAlgorithms.ipynb) | [Contents](index.ipynb) |  \n",
        "\n",
        "<a href=\"https://colab.research.google.com/github/csaybar/EEwPython/blob/master/9_SpecializedAlgorithms.ipynb\"><img align=\"left\" src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\" title=\"Open and Execute in Google Colaboratory\"></a>"
      ]
    }
  ]
}